package com.wlcj.www.web;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.wlcj.constant.Global;
import com.wlcj.www.model.main.Content;
import com.wlcj.www.model.product.Product;
import com.wlcj.www.model.product.UnfinishedProduct;
import com.wlcj.www.service.IndexService;
import com.wlcj.www.service.ProductService;

public class ProductListAction extends BaseAction {
	
	private ProductService productService = s(ProductService.class);
	private IndexService indexService = s(IndexService.class);
	
	public void index() {
		//Page<UnfinishedProduct> page = productService.getUnfinishedProductPage(null, null, null, null, null, null, 1);
		
		setAttr("ad1", indexService.getChannelAd(Global.PRODUCT_CHANNEL_AD1_ID));
		setAttr("ad2", indexService.getChannelAd(Global.PRODUCT_CHANNEL_AD2_ID));
		setAttr("ad3", indexService.getChannelAd(Global.PRODUCT_CHANNEL_AD3_ID));
		
		//setAttr("page", page);
	}
	
	public void indexPage() {
		int pageNo = getParaToInt("pageNo");
		Integer level = getParaToInt("level", null);
		Integer year = getParaToInt("year", null);
		Integer date = getParaToInt("date", null);
		Integer pid = getParaToInt("pid", null);
		Integer orderby = getParaToInt("orderby", null);
		String keywords = getPara("keywords", null);
		Page<UnfinishedProduct> page = productService.getUnfinishedProductPage(level, year, date, pid, orderby, keywords, pageNo);
		setAttr("page", page);
		renderJsp("list.jsp");
	}
	
	public void hot() {
		setAttr("hots", productService.getHotPlatforms());
	}
	
	public void pop() {
		setAttr("pops", productService.getPopProductTop10());
	}
	
	public void productList(){
		//int pageNo = getParaToInt("pageNo");
		Integer[] remen = getParaValuesToInt("remen[]");
		Integer[] anquan = getParaValuesToInt("anquan[]");
		Integer[] touzi = getParaValuesToInt("touzi[]");
		Integer[] plat = getParaValuesToInt("plat[]");
		Integer[] nianhua = getParaValuesToInt("nianhua[]");
		String paixu = getPara("paixu");
		Page<UnfinishedProduct> page = productService.getUnfinishedProductPage(remen,anquan,touzi,plat,nianhua,paixu,1);
		// 查询已经对接的平台
		// 广告位
		int[] guanggaoweiids = new int[]{2467,2472,2476};
		List<Content> guanggaowei = Content.dao.getListByIds(guanggaoweiids);
		setAttr("guanggaowei", guanggaowei);
		setAttr("page", page);
		setAttr("productsMessage", UnfinishedProduct.dao.getMessageBy());
		setAttr("remen", remen!=null?remen[0]:null);
		setAttr("touzi", touzi!=null?touzi[0]:null);
	}
	
	public void indexPage2() {
		int pageNo = getParaToInt("pageNo");
		Integer level = getParaToInt("level", null);
		Integer year = getParaToInt("year", null);
		Integer date = getParaToInt("date", null);
		Integer pid = getParaToInt("pid", null);
		Integer orderby = getParaToInt("orderby", null);
		String keywords = getPara("keywords", null);
		Page<UnfinishedProduct> page = productService.getUnfinishedProductPage(level, year, date, pid, orderby, keywords, pageNo);
		
		setAttr("page", page);
		renderJsp("list2.jsp");
	}
	public void search(){
		int pageNo = getParaToInt("pageNo");
		Integer[] remen = getParaValuesToInt("remen[]");
		Integer[] anquan = getParaValuesToInt("anquan[]");
		Integer[] touzi = getParaValuesToInt("touzi[]");
		Integer[] plat = getParaValuesToInt("plat[]");
		Integer[] nianhua = getParaValuesToInt("nianhua[]");
		String paixu = getPara("paixu");
		Page<UnfinishedProduct> page = productService.getUnfinishedProductPage(remen,anquan,touzi,plat,nianhua,paixu,pageNo);
		
		setAttr("page", page);
		renderJsp("list2.jsp");
	}
	
	public void platNamesearch(){
		//String word = getPara("word");
		Page<UnfinishedProduct> page = productService.getPageByPlatName(1);
		int[] guanggaoweiids = new int[]{2467,2472,2476};
		List<Content> guanggaowei = Content.dao.getListByIds(guanggaoweiids);
		setAttr("guanggaowei", guanggaowei);
		setAttr("page", page);
		setAttr("productsMessage", UnfinishedProduct.dao.getMessageBy());
		renderJsp("productList.jsp");
	}
}
